define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/participants/index' + location.search,
                 //   add_url: 'member/participants/add',
                 //   edit_url: 'member/participants/edit',
                  //  del_url: 'member/participants/del',
                    ///multi_url: 'member/participants/multi',
                    //import_url: 'member/participants/import',
                    table: 'account',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 获取选中项
            $(document).on("click", ".btn-selected2", function () {
                var data= JSON.stringify(table.bootstrapTable('getSelections'));
                var url = $(this).attr('data-url');
              //  var aid = $(this).attr('data-value');
                if(!url) return false;
                Fast.api.ajax({
                    url:url,
                    type:'post',
                    data:{data:data},
                    dataType: "json",
                }, function(data, ret){
                    //成功的回调
                    Layer.alert(ret.msg);
                    Fast.api.close(data);
                    // table.bootstrapTable('refresh', {});
                    // Layer.close();
                    window.parent.location.reload();
                    // Layer.closeAll();
                    // return false;
                }, function(data, ret){
                    //失败的回调
                    Layer.alert(ret.msg);
                    Fast.api.close(data);
                    window.parent.location.reload();
                    // layer.alert(ret.msg);
                    //return false;
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});